﻿using System;
using System.Collections.Generic;
using System.Text;
using HotelManagement.Common;
using System.Data.Common;
using HotelManagement.DL.Helper;
using HotelManagement.Common.SQL;
using System.Data;

namespace HotelManagement.DL.DAO
{
    public class LoginDL
    {
        private readonly string SQL_PARA_NAME = "@name";
        private readonly string SQL_PARA_PWD = "@password";

        public int Authorization(ref User userInfo) 
        {
            int nResult = (int)ReturnType.SUCCESS;
            try
            {
                DBHelper dbHelper = DBHelperFactory.createDBHelper();
                DbCommand command = dbHelper.CreateCommandBySql(SqlFile.SQL_LOGIN_AUTHORIZATION);
                dbHelper.AddInParameter(command, SQL_PARA_NAME, DbType.String, userInfo.Name);
                dbHelper.AddInParameter(command, SQL_PARA_PWD, DbType.String, userInfo.Password);
                DataSet ds = dbHelper.ExecuteDataSetQuery(command);
                if (0 == ds.Tables.Count || 0 == ds.Tables[0].Rows.Count) 
                {
                    nResult = (int)ReturnType.FAILED;
                }
            }
            catch(Exception)
            {
                throw;
            }

            return nResult;
        }
    }
}
